package com.hotelmanage.hm.serviceImpl;

import com.hotelmanage.hm.mapper.RoomMapper;
import com.hotelmanage.hm.po.RoomPO;
import com.hotelmanage.hm.po.RoomPOExample;
import com.hotelmanage.hm.service.RoomService;
import com.hotelmanage.hm.vo.RoomVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {

    @Resource
    private RoomMapper roomMapper;


    @Override
    public List<RoomPO> getAll() {
        return roomMapper.selectByExample(new RoomPOExample());
    }

    @Override
    public int newRoom(RoomVO roomVO) {
        RoomPO roomPO = new RoomPO();
        roomPO.setHotelid(roomVO.getHotelid());
        roomPO.setName(roomVO.getName());
        roomPO.setNum(roomVO.getNum());
        roomPO.setPrice(roomVO.getPrice());
        roomPO.setSquare(roomVO.getSquare());
        return roomMapper.insert(roomPO);
    }

    @Override
    public int editRoom(RoomVO roomVO) {
        RoomPO roomPO = new RoomPO();
        BeanUtils.copyProperties(roomVO,roomPO);


        return roomMapper.updateByPrimaryKeySelective(roomPO);
    }

    @Override
    public RoomPO get(Integer id) {
        RoomPOExample roomPOExample = new RoomPOExample();
        roomPOExample.or().andIdEqualTo(id);

        return roomMapper.selectOneByExample(roomPOExample);
    }
}
